package org.ysu.controller;

import org.apache.tomcat.Jar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.ysu.common.JsonResult;
import org.ysu.pojo.Family;
import org.ysu.pojo.Poor;
import org.ysu.service.FamilyService;
import org.ysu.service.PoorService;

import java.util.List;

@RestController
@RequestMapping("/poor")
public class PoorController {
    @Autowired
    private PoorService poorService;

    @Autowired
    private FamilyService familyService;
    @GetMapping("/head")
    public List<Poor> getAllHead(){
        return poorService.getAllHead();
    }

    @GetMapping("/get/pid/{pid}")
    public JsonResult getFamilyByFPid(@PathVariable Integer pid){
        Poor poor=poorService.getById(pid);
        Family family = familyService.getFamily(poor.getFId());
        if(family.getFId()!=-1){
            return new JsonResult(1,"success",family);
        }
        return new JsonResult(0,"fail",null);
    }
    @GetMapping("getPoor/{id}")
    public Poor getPoor(@PathVariable Integer id){
        return poorService.getPoor(id);
    }


}
